package org.sgsm.dungeon.generator.method;

import org.sgsm.dungeon.generator.ObjectType;

public class MethodGet extends MethodCRUD
{
  public MethodGet()
  {
    super();
  }

  public void generateServiceImpl()
  {
    print(getSignature());
    up();
    print(getObjetOut().getName() + " result = null;");
    print("if( p" + getBean() + " != null)");
    up();
    print("Session session = getSession();");
    print("result =  (" + getObjetOut().getName()+ ") session.get(" + getObjetOut().getName() + ".class, p" + getBean() + ".getId());");
    print("session.close();");
    down();
    print("return result;");
    down();
  }

  public void generateName(String pPack, String pName)
  {
    _ObjetOut = new ObjectType(pPack, pName + "Type");
    _ObjetIn.add(new ObjectType(pPack, pName + "KeyType"));
    _ObjetIn.add(new ObjectType(pPack, pName + "ScenarioType"));
    _ObjetIn.add(getContext());
    setMethodName("get" + pName);
  }
}
